#ifndef LRU_INCLUDE
#define LRU_INCLUDE 1
#include<iostream>
#include"data.hpp"

using namespace std;

/*LRU struct*/
struct LRU_node
{
    bool isHead;
    bool isTail;
    int frameID;
    int pageID;
    LRU_node *front;
    LRU_node *next;
};

class LRU
{
protected:
    LRU_node head;       //head with no information
    LRU_node tail;      //tail with no information
    LRU_node *current;
    int LRU_len; 
    void init_head();
    void init_tail();

public:      
    LRU();      //create LRU
    ~LRU();     //drop LRU
    
    void init_LRU();        //include init_head and init_tail
    int return_len();
    bool isfull();
    bool isempty();
    LRU_node* return_head();     //return the node after head
    LRU_node* return_tail();     //return the node before tail
    void insert_node(LRU_node *new_node);        //insert a new node before tail
    void insert_new_node(int pageID, int frameID);
    void drop_node(LRU_node *node);
    int drop_head();       //drop the node after head
    /* adjust the LRU */
    void adjust_LRU(LRU_node *node);
    void adjust_page(int page_num);
    
};

/* used to storage the rest frameID */
class frame_LRU:public LRU
{
public:
    frame_LRU();        
    ~frame_LRU();
    void init_frame();
    LRU_node* victim_node();     //return the first node
};

#endif

